<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="任务状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择任务状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.rush_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="频率/s" prop="frequency">
        <el-input
          v-model="queryParams.frequency"
          placeholder="请输入频率/s"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:ahstask:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:ahstask:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:ahstask:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:ahstask:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="ahstaskList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="任务状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.rush_status"
            :value="scope.row.status"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="分类ID"
        align="center"
        prop="gaeaCategoryId"
        v-if="false"
      />
      <el-table-column
        label="物品分类"
        align="center"
        prop="gaeaCategoryName"
        show-overflow-tooltip
      />
      <el-table-column
        label="品牌ID"
        align="center"
        prop="gaeaBrandId"
        v-if="false"
      />
      <el-table-column
        label="品牌"
        align="center"
        prop="gaeaBrandName"
        show-overflow-tooltip
      />
      <el-table-column
        label="具体型号ID"
        align="center"
        prop="gaeaProductId"
        v-if="false"
      />
      <el-table-column
        label="具体型号"
        align="center"
        prop="gaeaProductName"
        width="200"
        show-overflow-tooltip
      />
      <el-table-column
        label="成色ID"
        align="center"
        prop="gaeaFinenessIds"
        v-if="false"
      />
      <el-table-column
        label="成色"
        align="center"
        prop="gaeaFinenessNames"
        width="200"
        show-overflow-tooltip
      />
      <el-table-column
        label="电池效率ID"
        align="center"
        prop="gaeaPricePpvIds"
        v-if="false"
      />
      <el-table-column
        label="电池效率"
        align="center"
        prop="gaeaPricePpvNames"
        width="200"
        show-overflow-tooltip
      />
      <el-table-column
        label="型号特殊参数ID"
        align="center"
        prop="gaeaSkuPpvIds"
        v-if="false"
      />
      <el-table-column
        label="型号特殊参数"
        align="center"
        prop="gaeaSkuPpvNames"
        width="400"
        show-overflow-tooltip
      />
      <el-table-column label="最低价" align="center" prop="minPrice" />
      <el-table-column label="最高价" align="center" prop="maxPrice" />
      <el-table-column
        label="排序方式"
        align="center"
        prop="sortValue"
        width="200"
      />
      <el-table-column label="批次" align="center" prop="pageIndex" />
      <el-table-column label="每批大小" align="center" prop="pageSize" />
      <el-table-column label="频率/s" align="center" prop="frequency" />
      <el-table-column
        label="操作"
        align="center"
        width="200"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:ahstask:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:ahstask:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改抢购任务对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="商品分类" prop="gaeaCategoryName">
          <el-select
            placeholder="请选择商品分类"
            v-model="form.gaeaCategoryName"
            @change="handleCategoryChange"
          >
            <el-option
              v-for="item in this.gaeaCategoryOptions"
              :key="item.gaeaCategoryId"
              :label="item.gaeaCategoryName"
              :value="item"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="商品品牌" prop="gaeaBrandName">
          <el-select
            placeholder="请选择商品品牌"
            v-model="form.gaeaBrandName"
            @change="handleBrandChange"
            :loading="brandLoading"
          >
            <el-option
              v-for="item in this.gaeaBrandOptions"
              :key="item.gaeaBrandId"
              :label="item.gaeaBrandName"
              :value="item"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="商品机型" prop="gaeaProductName">
          <el-select
            v-model="form.gaeaProductName"
            placeholder="请选择商品机型"
            @change="handleProductChange"
            :loading="productLoading"
          >
            <el-option
              v-for="item in this.gaeaProductOptions"
              :key="item.gaeaProductId"
              :label="item.gaeaProductName"
              :value="item"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="商品成色" prop="gaeaFinenessNames">
          <el-checkbox-group v-model="selectedFinenessList">
            <el-checkbox
              v-for="item in finenessInfoOptions"
              :key="item.gaeaFinenessId"
              :label="item"
              :value="item"
            >
              {{ item.gaeaFinenessName }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="最低价" prop="minPrice">
          <el-input v-model="form.minPrice" placeholder="请输入最低价">
            <template slot="append">元</template>
          </el-input>
          <span
            v-if="!Number.isInteger(Number(form.minPrice))"
            style="color: red"
            >请输入整数</span
          >
        </el-form-item>
        <el-form-item label="最高价" prop="maxPrice">
          <el-input v-model="form.maxPrice" placeholder="请输入最高价">
            <template slot="append">元</template>
          </el-input>
          <span
            v-if="!Number.isInteger(Number(form.maxPrice))"
            style="color: red"
            >请输入整数</span
          >
        </el-form-item>
        <el-form-item label="排序方式" prop="sortValue">
          <el-select v-model="form.sortValue" placeholder="请选择排序方式">
            <el-option
              v-for="item in this.sortOptions"
              :key="item.sortValue"
              :label="item.name"
              :value="item.sortValue"
            />
          </el-select>
        </el-form-item>

        <!-- ############### 特殊参数处理 ################### -->

        <el-form-item label="电池效率" prop="ppvList473">
          <el-checkbox-group v-model="selectedPpvList473">
            <el-checkbox
              v-for="item in ppvList473"
              :key="item.gaeaPpvId"
              :label="item"
              :value="item"
            >
              {{ item.gaeaPpvName }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="购买渠道" prop="ppvList20">
          <el-checkbox-group v-model="selectedPpvList20">
            <el-checkbox
              v-for="item in ppvList20"
              :key="item.gaeaPpvId"
              :label="item"
              :value="item"
            >
              {{ item.gaeaPpvName }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="颜色" prop="ppvList21">
          <el-checkbox-group v-model="selectedPpvList21">
            <el-checkbox
              v-for="item in ppvList21"
              :key="item.gaeaPpvId"
              :label="item"
              :value="item"
            >
              {{ item.gaeaPpvName }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="内存" prop="ppvList22">
          <el-checkbox-group v-model="selectedPpvList22">
            <el-checkbox
              v-for="item in ppvList22"
              :key="item.gaeaPpvId"
              :label="item"
              :value="item"
            >
              {{ item.gaeaPpvName }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="网络制式" prop="ppvList26">
          <el-checkbox-group v-model="selectedPpvList26">
            <el-checkbox
              v-for="item in ppvList26"
              :key="item.gaeaPpvId"
              :label="item"
              :value="item"
            >
              {{ item.gaeaPpvName }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <!-- <div v-for="sku in skuPpnList" :key="sku.gaeaPpnId">
          <el-form-item :label="sku.gaeaPpnName" :prop="`sku_${sku.gaeaPpnId}`">
            <el-checkbox-group v-model="selectSkuPpnList[sku.gaeaPpnId]">
              <el-checkbox
                v-for="ppv in sku.ppvList"
                :key="ppv.gaeaPpvId"
                :label="ppv"
                :value="ppv"
              >
                {{ ppv.gaeaPpvName }}
              </el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </div> -->
        <!-- ############### 特殊参数处理 结束 ################### -->

        <el-form-item label="批次" prop="pageIndex">
          <el-input v-model="form.pageIndex" placeholder="请输入批次">
          </el-input>
          <span
            v-if="!Number.isInteger(Number(form.pageIndex))"
            style="color: red"
            >请输入整数</span
          >
        </el-form-item>
        <el-form-item label="每批大小" prop="pageSize">
          <el-input v-model="form.pageSize" placeholder="请输入每批大小">
          </el-input>
          <span
            v-if="!Number.isInteger(Number(form.pageSize))"
            style="color: red"
            >请输入整数</span
          >
        </el-form-item>
        <el-form-item label="任务状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in dict.type.rush_status"
              :key="dict.value"
              :label="dict.value"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item label="频率/s" prop="frequency">
          <el-input v-model="form.frequency" placeholder="请输入频率/s" />
          <span
            v-if="!Number.isInteger(Number(form.frequency))"
            style="color: red"
            >请输入整数</span
          >
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listAhstask,
  getAhstask,
  delAhstask,
  addAhstask,
  updateAhstask,
  getCategoryBrand,
  getProduct,
  getPpvAssociation,
} from "@/api/system/ahstask";
export default {
  name: "Ahstask",
  dicts: ["rush_status"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 抢购任务表格数据
      ahstaskList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        gaeaCategoryId: null,
        gaeaCategoryName: null,
        gaeaBrandId: null,
        gaeaBrandName: null,
        gaeaProductId: null,
        gaeaProductName: null,
        gaeaFinenessIds: null,
        gaeaFinenessNames: null,
        gaeaPricePpvIds: null,
        gaeaPricePpvNames: null,
        gaeaSkuPpvIds: null,
        gaeaSkuPpvNames: null,
        minPrice: null,
        maxPrice: null,
        sortValue: null,
        pageIndex: null,
        pageSize: null,
        status: null,
        frequency: null,
      },
      // 表单参数
      form: {
        id: null,
        gaeaCategoryId: null,
        gaeaCategoryName: null,
        gaeaBrandId: null,
        gaeaBrandName: null,
        gaeaProductId: null,
        gaeaProductName: null,
        gaeaFinenessIds: [],
        gaeaFinenessNames: [],
        gaeaPricePpvIds: {},
        gaeaPricePpvNames: {},
        gaeaSkuPpvIds: {},
        gaeaSkuPpvNames: {},
        minPrice: null,
        maxPrice: null,
        sortValue: null,
        pageIndex: null,
        pageSize: null,
        status: null,
        frequency: null,
      },
      // 表单校验
      rules: {},
      // 新增数据选项
      gaeaCategoryOptions: [
        { gaeaCategoryId: 655, gaeaCategoryName: "手机" },
        { gaeaCategoryId: 2694, gaeaCategoryName: "平板电脑" },
        { gaeaCategoryId: 672, gaeaCategoryName: "笔记本" },
        { gaeaCategoryId: 12348, gaeaCategoryName: "智能手表" },
        { gaeaCategoryId: 842, gaeaCategoryName: "耳机/耳麦" },
        { gaeaCategoryId: 5012, gaeaCategoryName: "相机机身" },
      ],
      brandLoading: false,
      productLoading: false,
      gaeaBrandOptions: [],
      gaeaProductOptions: [],
      sortOptions: [
        { sortValue: "sort_composite", name: "综合排序" },
        { sortValue: "sort_price_asc", name: "价格最低" },
        { sortValue: "sort_price_desc", name: "价格最高" },
      ],
      finenessInfoOptions: [
        { gaeaFinenessId: 100, gaeaFinenessName: "准新品" },
        { gaeaFinenessId: 99, gaeaFinenessName: "99新" },
        { gaeaFinenessId: 95, gaeaFinenessName: "95新" },
        { gaeaFinenessId: 90, gaeaFinenessName: "9成新" },
        { gaeaFinenessId: 80, gaeaFinenessName: "8成新" },
        { gaeaFinenessId: 79, gaeaFinenessName: "微瑕" },
        { gaeaFinenessId: 78, gaeaFinenessName: "瑕疵" },
        { gaeaFinenessId: 70, gaeaFinenessName: "7成新" },
      ],
      selectedFinenessList: [],
      // 特殊参数
      // pricePpnList: [],
      // selectedPricePpnList: [],
      // skuPpnList: [],
      // selectedSkuPpnList: [],
      //电池效率
      ppvList473: [],
      selectedPpvList473: [],
      //购买渠道
      ppvList20: [],
      selectedPpvList20: [],
      //颜色
      ppvList21: [],
      selectedPpvList21: [],
      //内存
      ppvList22: [],
      selectedPpvList22: [],
      //网络制式
      ppvList26: [],
      selectedPpvList26: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询抢购任务列表 */
    getList() {
      this.loading = true;
      listAhstask(this.queryParams).then((response) => {
        this.ahstaskList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        gaeaCategoryId: null,
        gaeaCategoryName: null,
        gaeaBrandId: null,
        gaeaBrandName: null,
        gaeaProductId: null,
        gaeaProductName: null,
        gaeaFinenessIds: [],
        gaeaFinenessNames: [],
        gaeaPricePpvIds: {},
        gaeaPricePpvNames: {},
        gaeaSkuPpvIds: null,
        gaeaSkuPpvNames: null,
        minPrice: null,
        maxPrice: null,
        sortValue: null,
        pageIndex: null,
        pageSize: null,
        status: null,
        frequency: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加抢购任务";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getAhstask(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改抢购任务";
        //加载已选择的成色
        this.selectedFinenessList = response.data.gaeaFinenessIds.map(
          (id, index) => {
            return {
              gaeaFinenessId: id,
              gaeaFinenessName: response.data.gaeaFinenessNames[index],
            };
          }
        );
        //电池效率
        const ids473 = response.data.gaeaPricePpvIds["473"];
        this.selectedPpvList473 = Array.isArray(ids473)
          ? ids473.map((id) => {
              return {
                gaeaPpvId: id,
                gaeaPpvName: response.data.gaeaPricePpvNames["473"][id],
              };
            })
          : [];
        //购买渠道
        const ids20 = response.data.gaeaSkuPpvIds["20"];
        this.selectedPpvList20 = Array.isArray(ids20)
          ? ids20.map((id) => {
              return {
                gaeaPpvId: id,
                gaeaPpvName: response.data.gaeaSkuPpvNames["20"][id],
              };
            })
          : [];
        //颜色
        const ids21 = response.data.gaeaSkuPpvIds["21"];
        this.selectedPpvList21 = Array.isArray(ids21)
          ? ids21.map((id) => {
              return {
                gaeaPpvId: id,
                gaeaPpvName: response.data.gaeaSkuPpvNames["21"][id],
              };
            })
          : [];
        //内存
        const ids22 = response.data.gaeaSkuPpvIds["22"];
        this.selectedPpvList22 = Array.isArray(ids22)
          ? ids22.map((id) => {
              return {
                gaeaPpvId: id,
                gaeaPpvName: response.data.gaeaSkuPpvNames["22"][id],
              };
            })
          : [];
        //网络制式
        const ids26 = response.data.gaeaSkuPpvIds["26"];
        this.selectedPpvList26 = Array.isArray(ids26)
          ? ids26.map((id) => {
              return {
                gaeaPpvId: id,
                gaeaPpvName: response.data.gaeaSkuPpvNames["26"][id],
              };
            })
          : [];
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        // 成色
        const gaeaFinenessIds = this.selectedFinenessList.map(
          (item) => item.gaeaFinenessId
        );
        const gaeaFinenessNames = this.selectedFinenessList.map(
          (item) => item.gaeaFinenessName
        );
        this.form.gaeaFinenessIds = gaeaFinenessIds;
        this.form.gaeaFinenessNames = gaeaFinenessNames;

        // 特殊参数
        //电池效率
        console.log(this.selectedPpvList473);
        const ids473 = this.selectedPpvList473.map((item) => item.gaeaPpvId);
        const names473 = this.selectedPpvList473.map(
          (item) => item.gaeaPpvName
        );
        this.form.gaeaPricePpvIds = {
            "473": ids473
        };
        this.form.gaeaPricePpvNames = {
            "电池效率": names473
        };
        this.form.gaeaSkuPpvIds = {
            "20": this.selectedPpvList20.map((item) => item.gaeaPpvId), //购买渠道
            "21": this.selectedPpvList21.map((item) => item.gaeaPpvId), //颜色
            "22": this.selectedPpvList22.map((item) => item.gaeaPpvId), //内存
            "26": this.selectedPpvList26.map((item) => item.gaeaPpvId)  //网络制式
        };
        this.form.gaeaSkuPpvNames = {
            "购买渠道": this.selectedPpvList20.map((item) => item.gaeaPpvName),
            "颜色": this.selectedPpvList21.map((item) => item.gaeaPpvName),
            "内存": this.selectedPpvList22.map((item) => item.gaeaPpvName),
            "网络制式": this.selectedPpvList26.map((item) => item.gaeaPpvName)
        };
        if (valid) {
          if (this.form.id != null) {
            updateAhstask(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAhstask(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除抢购任务编号为"' + ids + '"的数据项？')
        .then(function () {
          return delAhstask(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/ahstask/export",
        {
          ...this.queryParams,
        },
        `ahstask_${new Date().getTime()}.xlsx`
      );
    },
    // 分类改变
    handleCategoryChange(val) {
      this.form.gaeaCategoryId = val.gaeaCategoryId;
      this.form.gaeaCategoryName = val.gaeaCategoryName;
      this.form.gaeaBrandName = null;
      this.form.gaeaBrandId = null;
      this.form.gaeaProductName = null;
      this.form.gaeaProductId = null;
      this.form.gaeaPricePpvIds = null;
      this.form.gaeaPricePpvNames = null;
      this.form.gaeaSkuPpvIds = null;
      this.form.gaeaSkuPpvNames = null;
      this.loadBrandList();
    },
    // 品牌改变
    handleBrandChange(val) {
      this.form.gaeaBrandName = val.gaeaBrandName;
      this.form.gaeaBrandId = val.gaeaBrandId;
      this.form.gaeaProductName = null;
      this.form.gaeaProductId = null;
      this.form.gaeaPricePpvIds = null;
      this.form.gaeaPricePpvNames = null;
      this.form.gaeaSkuPpvIds = null;
      this.form.gaeaSkuPpvNames = null;
      this.loadProductList();
    },
    // 机型改变
    handleProductChange(val) {
      this.form.gaeaProductName = val.gaeaProductName;
      this.form.gaeaProductId = val.gaeaProductId;
      this.form.gaeaPricePpvIds = null;
      this.form.gaeaPricePpvNames = null;
      this.form.gaeaSkuPpvIds = null;
      this.form.gaeaSkuPpvNames = null;
      this.loadPpvAssociation();
    },
    // 获取品牌列表
    async loadBrandList() {
      this.brandLoading = true;
      try {
        const res = await getCategoryBrand(this.form.gaeaCategoryId);
        if (res.code === 200 && res.data.length > 0) {
          this.gaeaBrandOptions = res.data[0].brands || [];
        }
      } catch (error) {
        console.error("获取品牌列表失败:", error);
      } finally {
        this.brandLoading = false;
      }
    },
    // 获取机型列表
    async loadProductList() {
      this.productLoading = true;
      try {
        const res = await getProduct(
          this.form.gaeaCategoryId,
          this.form.gaeaBrandId
        );
        if (res.code === 200 && res.data.length > 0) {
          this.gaeaProductOptions = res.data || [];
        }
      } catch (error) {
        console.error("获取机型列表失败:", error);
      } finally {
        this.productLoading = false;
      }
    },
    async loadPpvAssociation() {
      const res = await getPpvAssociation(
        this.form.gaeaCategoryId,
        this.form.gaeaBrandId,
        this.form.gaeaProductId
      );
      //刷新参数选项
      if (res.code === 200) {
        res.data.pricePpnList.forEach((item) => {
          if (item.gaeaPpnId === 473) {
            this.ppvList473 = item.ppvList;
          }
        });
        res.data.skuPpnList.forEach((item) => {
          if (item.gaeaPpnId === 20) {
            this.ppvList20 = item.ppvList;
          } else if (item.gaeaPpnId === 21) {
            this.ppvList21 = item.ppvList;
          } else if (item.gaeaPpnId === 22) {
            this.ppvList22 = item.ppvList;
          } else if (item.gaeaPpnId === 26) {
            this.ppvList26 = item.ppvList;
          }
        });
      }
    },
    // 修改表单回显时需要调用
    async handleEdit(row) {
      this.form = { ...row };
      // 加载品牌和机型选项
      await this.loadBrandList();
      if (this.form.gaeaBrandId) {
        await this.loadProductList();
      }
    },
  },
};
</script>
